import java.util.InputMismatchException;
import java.util.Random;
import java.util.Scanner;

public class szl {
    static int count = 2;
    public static void main(String[] args) {
        System.out.println("欢迎来到猜数字小游戏");
        Random r = new Random();
        int number = r.nextInt(10);
        Scanner scan = new Scanner(System.in);
        try {
            while (count >= 0) {
                if (count == 0) {
                    System.out.println("你是否要继续游戏");
                    String xx =  scan.next();
                    System.out.println(xx);
                    if(xx.equals("y")){
                        count = 7;
                        number = r.nextInt(10);
                        System.out.println("游戏已从新开始，请输入你猜测的数字");
                    }else{
                        count =-1;
                        System.out.println("游戏结束");
                    }
                } else {
                    int guess = scan.nextInt();
                    if (guess > number) {
                        System.out.println("你猜大了" + "  您还" + count + "次机会");
                        count--;
                    } else if (guess < number) {
                        System.out.println("您猜小了" + "您还" + count + "次机会");
                        count--;
                    } else {
                        System.out.println("您猜对了");
                        break;
                    }

                }
            }

        }catch (InputMismatchException e){
            System.out.println("请输入数字");
        }


    }



}
